package com.zhonghui.modlules.user.eshopMapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.zhonghui.common.eshopMapper.CoreMapper;
import com.zhonghui.modlules.user.eshopDomain.UserBill;
import com.zhonghui.modlules.user.eshopDto.MUserBillDto;
import com.zhonghui.modlules.user.eshopVo.BillVo;
import com.zhonghui.modlules.user.eshopVo.SignVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserBillMapper extends CoreMapper<UserBill> {
    /**
     *   # 根据状态  明细类型 pm=获得 明细种类 用户uid 进行
     *   查询求和 明细数字 不为 NULL 返回求和的 否则返回 0
     */
    @Select({"select IFNULL(sum(number),0) from user_bill where status=1 and type='recharge' and pm=1 and category='now_money' and uid=#{uid}"})
    double sumRechargePrice(@Param("uid") Long uid);
    @Select({"SELECT DATE_FORMAT(a.create_time,'%Y-%m-%d') as addTime,a.title,a.number FROM user_bill a INNER JOIN eshop_user u ON u.uid=a.uid WHERE a.category = 'integral' AND a.type = 'sign' AND a.status = 1 AND a.uid = #{uid} ORDER BY a.create_time DESC"})
    List<SignVo> getSignList(@Param("uid") Long uid, Page page);

    @Select({"SELECT DATE_FORMAT(create_time,'%Y-%m') as time,group_concat(id SEPARATOR ',') ids  FROM user_bill ${ew.customSqlSegment}"})
    List<BillVo> getBillList(@Param("ew") Wrapper<UserBill> userWrapper, Page page);

    @Select({"SELECT DATE_FORMAT(create_time,'%Y-%m-%d %H:%i') as add_time,title,number,pm  FROM user_bill ${ew.customSqlSegment}"})
    List<MUserBillDto> getUserBillList(@Param("ew") Wrapper<UserBill> userWrapper);
}
